import Image  # from PIL package
import numpy as np

file = "binaryalphadigs.jpg"

fullimage = Image.open(file)
n_rows = 36
n_cols = 39
dx = fullimage.size[0] / n_cols
dy = fullimage.size[1] / n_rows

def crop(j, i, asarray=True):
  im = fullimage.crop((i*dx, j*dy, (i+1)*dx, (j+1)*dy))
  return np.asarray(im).astype('float')/255 if asarray else im
  